const { defineConfig } = require("@vue/cli-service");
// 获取当前环境，是否是生产环境
const isProduction = process.env.NODE_ENV === "production";
const path = require("path");

const resolve = dir => {
    return path.join(__dirname, dir);
};
module.exports = defineConfig({
    transpileDependencies: true,

    chainWebpack: config => {
        // 别名
        config.resolve.alias
            .set("@", resolve("src")) // key,value自行定义，比如.set('@@', resolve('src/components'))
            .set("_root", resolve("/"));

        // 这块是因为要生成库项目
        // config.plugins.delete("html");
        // config.plugins.delete("preload"); //预加载
        // config.plugins.delete("prefetch");

        // 全局使用的scss样式
        // 这个全局的scss样式，不要生成有内容的样式，最好写变量或mixin，不然 每个使用scss的地方都会生成一遍
        const oneOfsMap = config.module.rule("scss").oneOfs.store;
        oneOfsMap.forEach(item => {
            item.use("sass-resources-loader")
                .loader("sass-resources-loader")
                .options({
                    // Provide path to the file with resources
                    //resources: "./src/styles/variables.scss"
                    // Or array of paths
                    //resources: ["./src/styles/variables.scss", "./src/styles/mixin.scss"]
                    resources: ["./src/styles/variables.scss"]
                })
                .end();
        });
    },

    configureWebpack: config => {
        // 下边的意思是，排除第三方引用
        // if (isProduction) {
        //     config.externals = {
        //         vue: "Vue",
        //         lodash: "_",
        //         "awe-dnd": "VueDragging",
        //         axios: "axios",
        //         jquery: "jQuery",
        //         "js-cookie": "Cookies",
        //         dayjs: "dayjs",
        //         "vue-router": "VueRouter",
        //         "core-js": "coreJs",
        //         "vue-lazyload": "VueLazyload",
        //         "element-ui": "ELEMENT",
        //         sortablejs: "Sortable",
        //         vuedraggable: "vuedraggable",
        //         nprogress: "NProgress"
        //     };
        //     for (const key in config.externals) {
        //         const element = config.externals[key];
        //         config.externals[key] = {
        //             root: element,
        //             amd: element,
        //             commonjs: key,
        //             commonjs2: key
        //         };
        //     }
        // }
    },
    pluginOptions: {
        windicss: {
            // see https://github.com/windicss/vite-plugin-windicss/blob/main/packages/plugin-utils/src/options.ts
        }
    }
});
